package com.nuc.list1;

import java.util.ArrayList;
import java.util.List;

/**
 * Time    : 2023/3/30 8:57
 * Author  : 王摇摆
 * FileName: Demo1.java
 * Software: IntelliJ IDEA 2020.2.2
 * Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
 * list中添加，获取，删除元素
 */

public class Demo1 {
    public static void main(String[] args) {

        List<String> person = new ArrayList<>();//person表示创建的类对象的名字，string表示列表中元素的数据类型
        //List的add方法
        person.add("jackie");
        person.add("peter");
        person.add("annie");
        person.add("martin");
        person.add("marry");
        person.add("wgw");


        System.out.println("The number of the List is " + person.size());
        for (String pers : person) {
            System.out.print(pers + " ");

        }
        System.out.println();
        System.out.println("-------------");

        //List的remove方法
        person.remove(2);
        person.remove("marry");

        System.out.println("The number of the List is " + person.size());
        for (String pers : person) {
            System.out.print(pers + " ");
        }
        System.out.println();
        System.out.println("-------------");

        //List的get方法
        String per;
        per=person.get(3);
        System.out.println("Now the value of per is "+per );

        //for循环将List所有内容编译
        for (String pers:person){
            System.out.print(pers+" ");
        }
        System.out.println();
        System.out.println("-------------");
    }
}
